using AndyPike.Commons.TestSupport;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using WatiN.Core;

namespace AndyPike.Snowflake.Web.Tests.Acceptance
{
    public class When_logging_into_the_site : AcceptanceTestBase
    {
        [Test, Category("Acceptance")]
        public void Should_display_the_sign_in_controls()
        {
            using (var browser = new IE(BuildUrl("Account", "Login")))
            {
                Assert.That(browser.TextField(Find.ById("credentials_userName")).Exists, Is.True);
                Assert.That(browser.TextField(Find.ById("credentials_password")).Exists, Is.True);
                Assert.That(browser.Button(Find.ById("signIn")).Exists, Is.True);
            }
        }

        [Test, Category("Acceptance")]
        public void Should_display_an_error_message_if_login_failed()
        {
            using (var browser = new IE(BuildUrl("Account", "Login")))
            {
                browser.TextField(Find.ById("credentials_userName")).TypeText("this_is_invalid");
                browser.TextField(Find.ById("credentials_password")).TypeText("this_is_invalid");
                browser.Button(Find.ById("signIn")).Click();

                Assert.That(browser.ContainsText("Invalid user name or password, please try again."));
            }
        }

        [Test, Category("Acceptance")]
        public void Should_display_the_users_dashboard_if_login_was_successful()
        {
            using (var browser = new IE(BuildUrl("Account", "Login")))
            {
                browser.TextField(Find.ById("credentials_userName")).TypeText("andy.pike");
                browser.TextField(Find.ById("credentials_password")).TypeText("andy123");
                browser.Button(Find.ById("signIn")).Click();

                Assert.That(browser.Title, Is.EqualTo(string.Format("{0} - My Dashboard", productName)));
            }
        }
    }
}